package com.preskool.service.impl;

import com.preskool.dto.TeacherVo;
import com.preskool.mapper.TeacherMapper;
import com.preskool.po.Teacher;
import com.preskool.po.TeacherExample;
import com.preskool.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author kennyzzz
 * @Data 2021/1/7 14:19
 */
@Service
public class TeacherServiceImpl implements TeacherService {
    @Autowired(required = false)
    private TeacherMapper teacherMapper;


    @Override
    public List<TeacherVo> findTeachersByPage(Integer currentPage, Integer pageSize, String sortName) {
        TeacherExample example = new TeacherExample();
        example.setOffset((currentPage-1)*pageSize);
        example.setLimit(pageSize);
        example.setOrderByClause(sortName);

        return teacherMapper.selectTeachersByPage(example);
    }

    @Override
    public Teacher findTeacherByTid(Integer tid) {
        return teacherMapper.selectByPrimaryKey(tid);
    }

    @Override
    public int addTeacher(Teacher teacher) {
        return teacherMapper.insertSelective(teacher);
    }

    @Override
    public int deleteTeacherByTid(Integer tid) {
        return teacherMapper.deleteByPrimaryKey(tid);
    }

    @Override
    public int updateTeacher(Teacher teacher) {
        return teacherMapper.updateByPrimaryKey(teacher);
    }
}
